package com.commerceE.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.commerceE.dao.UserDao;
import com.commerceE.domain.User;
import com.commerceE.service.UserService;

@Transactional(readOnly = false)
public class UserServiceImpl implements UserService{

	@Autowired
	private UserDao userDao;

	public void insertUser(User user){
		userDao.insert(user);
	}
	
	public void updateUser(User user){
		userDao.update(user);
	}
	
	public User selectUserByUserId(Long userid){
		return userDao.get(userid);
	}
	
	public void deleteUser(Long userid){
		userDao.delete(userid);
	}
	
	public boolean checkUserNameAvailability(String username){
		if(StringUtils.isBlank(username)){
			return false;
		}else if(userDao.countUserByUsername(username)>0){
			return false;
		}else{
			return true;
		}
	}
	
	public boolean checkEmailAvailability(String email){
		if(StringUtils.isBlank(email)){
			return false;
		}else if(userDao.countUserByEmail(email)>0){
			return false;
		}else{
			return true;
		}
	}
	
	public User getUserByUsernameAndPassword(String username, String password){
		return userDao.getUserByUsernameAndPassword(username,password);
	}
	
	//seter and getter
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
}
